/**
 * @param {number} x
 * @return {number}
 */
var reverse = function (x) {
  let isPositive = true; // 是否正数
  if (x < 0) {
    isPositive = false;
    x = x * -1;
  }
  let numStr = x.toString();
  let reverseStr = "";
  for (let i = numStr.length - 1; i >= 0; i--) {
    reverseStr += numStr[i];
  }
  let newNum = Number(reverseStr);

  if (!isPositive) {
    newNum = newNum * -1;
  }
  console.log(newNum);
  if (newNum < -Math.pow(2, 32) || newNum > Math.pow(2, 32) - 1) {
    return 0;
  } else {
    return newNum;
  }
};
// var x = 321;
// var x = -123;
// var x = 0;
var x = 100000000;
var result = reverse(x);
console.log(result);
